home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 258 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.std.c
  4. Subject: Re: atexit() and return from main()
  5. Date: 31 Jan 1996 21:27:38 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan31142738@qcd.lanl.gov>
  8. References: <4dhfja$j50@fg70.rz.uni-karlsruhe.de> <4diicg$i9e@lyra.csx.cam.ac.uk>
  9.     <TANMOY.96Jan22084309@qcd.lanl.gov>
  10.     <DLMLL6.A0H@ukpsshp1.serigate.philips.nl>
  11.     <4emq9l$2fn@hammy.lonestar.org>
  12. NNTP-Posting-Host: qcd.lanl.gov
  13. Mime-Version: 1.0
  14. Content-Type: text
  15. In-reply-to: gordon@hammy.lonestar.org's message of 30 Jan 1996 22:13:41 -0600
  16.  
  17. In article <4emq9l$2fn@hammy.lonestar.org> gordon@hammy.lonestar.org
  18. (Gordon Burditt) writes: 
  19. <snip>
  20.    ANSI C Classic 2.1.2.2.3 Program Termination
  21.    A RETURN FROM THE INITIAL CALL TO THE MAIN FUNCTION IS EQUIVALENT
  22.    TO CALLING THE EXIT FUNCTION with the value returned by the main
  23.    function as its argument.
  24.    ...
  25.    I claim that longjmp()ing out of an atexit function into main
  26.    causes undefined behavior because main() has already returned
  27.    (or, equivalently, called exit()) between the setjmp and
  28.    longjmp calls.
  29.  
  30.    In fact, calling exit() may not unwind the stack like returning
  31.    from main() does, so you might get away with it, but there's
  32.    no guarantee.
  33.  
  34. Isn't the TC going to clarify that return from main is not exactly the
  35. same as calling exit? Or is it just planning to restrict the
  36. clarification to the situation with respect to the local variables?
  37.  
  38. In any case, without a change in the standard, I would consider that
  39. the wording in the standard is that `a return ... is equivalent to
  40. calling the exit function...' not the other way round. So, I would
  41. interpret this as saying that return from main cannot unwind stack
  42. either, exactly as exit cannot: not that both can.
  43.  
  44. Cheers
  45. Tanmoy
  46. --
  47. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  48. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  49. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  50. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  51. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  52. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  53.